package com.web.config;

import com.web.netty.WebServer;
import com.web.netty.thread.NettyOutThread;
import com.web.observers.DataObservable;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;

@Component
public class Global {

    private LinkedBlockingQueue<byte[]> inQueue;
    private LinkedBlockingQueue<byte[]> outQueue;
    private ConcurrentMap<String, Channel> channelMap;
    private DataObservable deviceResponseObservable;
    private DataObservable deviceResultObservable;
    private DataObservable gateWayBridgeResponseObservable;

    @Value("${gateWayBridge.ip}")
    private String gateWayBridgeIp;


    @Autowired
    NettyOutThread nettyOutThread;

    @Autowired
    WebServer webServer;

    private Global() {
    }

    @Bean
    public LinkedBlockingQueue<byte[]> getInQueue() {
        return new LinkedBlockingQueue<>();
    }

    @Bean
    public LinkedBlockingQueue<byte[]> getOutQueue() {
        return new LinkedBlockingQueue<>();
    }

    @Bean
    public ConcurrentMap<String, Channel> getChannelMap() {
        return new ConcurrentHashMap<>();
    }

    @Bean
    public DataObservable getDeviceResponseObservable() {
        return new DataObservable();
    }
    @Bean
    public DataObservable getDeviceResultObservable() {
        return new DataObservable();
    }
    @Bean
    public DataObservable getGateWayBridgeResponseObservable() {
        return new DataObservable();
    }

    @Bean
    public String getGateWayBridgeIp() {
        return gateWayBridgeIp;
    }


}

